(function(e) {
    var f = function() {},
        b = mobiscroll,
        a = b.$,
        d = b.util,
        c = d.getCoord,
        g = d.testTouch;
    b.classes.Slider = function(K, a5, a6) {
        var j, M, T, s, R, n, y, U, q, w, I, Y, a2, J, z, V, r, A, B, Q, u, a3, p, k, x, t, l, m, H, G, X, P, C, L, i, h = this,
            O = new Date();

        function W(b) {
            if (g(b, this) && !w && !K.disabled) {
                if (m.stopProp) {
                    b.stopPropagation();
                }
                w = true;
                x = false;
                I = false;
                G = c(b, 'X');
                X = c(b, 'Y');
                z = G;
                q.removeClass('mbsc-progress-anim');
                M = t ? a('.mbsc-slider-handle', this) : s;
                T = M.parent().addClass('mbsc-active');
                r = +M.attr('data-index');
                L = q[0].offsetWidth;
                J = q[0].getBoundingClientRect().left;
                if (b.type === 'mousedown') {
                    b.preventDefault();
                    a(document).on('mousemove', D).on('mouseup', E);
                }
            }
        }

        function D(a) {
            if (w) {
                z = c(a, 'X');
                V = c(a, 'Y');
                Y = z - G;
                a2 = V - X;
                if (Math.abs(Y) > 5 || x) {
                    x = true;
                    if (Math.abs(O - new Date()) > 50) {
                        O = new Date();
                        a4(z, m.round, a3);
                    }
                }
                if (x) {
                    a.preventDefault();
                } else if (Math.abs(a2) > 7) {
                    S(a);
                }
            }
        }

        function E(a) {
            if (w) {
                a.preventDefault();
                if (!t) {
                    q.addClass('mbsc-progress-anim');
                }
                a4(z, true, true);
                if (!x && !I) {
                    d.preventClick();
                    h._onTap(i[r]);
                }
                S();
            }
        }

        function Z() {
            if (w) {
                S();
            }
        }

        function _() {
            var b = h._readValue(a(this)),
                c = +a(this).attr('data-index');
            if (b !== i[c]) {
                i[c] = b;
                v(b, c);
            }
        }

        function $(a) {
            a.stopPropagation();
        }

        function a0(a) {
            a.preventDefault();
        }

        function a1(c) {
            var b;
            if (!K.disabled) {
                switch (c.keyCode) {
                    case 38:
                    case 39:
                        b = 1;
                        break;
                    case 40:
                    case 37:
                        b = -1;
                        break;
                }
                if (b) {
                    c.preventDefault();
                    if (!C) {
                        r = +a(this).attr('data-index');
                        v(i[r] + l * b, r, true);
                        C = setInterval(function() {
                            v(i[r] + l * b, r, true);
                        }, 200);
                    }
                }
            }
        }

        function F(a) {
            a.preventDefault();
            clearInterval(C);
            C = null;
        }

        function S() {
            w = false;
            T.removeClass('mbsc-active');
            a(document).off('mousemove', D).off('mouseup', E);
        }

        function a4(b, c, d) {
            var a = c ? Math.min(Math.round(Math.max((b - J) * 100 / L, 0) / H / l) * l * 100 / (p - k), 100) : Math.max(0, Math.min((b - J) * 100 / L, 100));
            if (u) {
                a = 100 - a;
            }
            v(Math.round((k + a / H) * P) / P, r, d, a);
        }

        function o(a) {
            return (a - k) * 100 / (p - k);
        }

        function N(b, c) {
            var a = j.attr(b);
            return a === e || a === '' ? c : a === 'true';
        }

        function v(a, b, j, d, l, f) {
            var g = s.eq(b),
                c = g.parent();
            a = Math.min(p, Math.max(a, k));
            if (f === e) {
                f = j;
            }
            if (Q) {
                if (b === 0) {
                    a = Math.min(a, i[1]);
                    y.css({
                        width: o(i[1]) - o(a) + '%',
                        left: u ? 'auto' : o(a) + '%',
                        right: u ? o(a) + '%' : 'auto'
                    });
                } else {
                    a = Math.max(a, i[0]);
                    y.css({
                        width: o(a) - o(i[0]) + '%'
                    });
                }
            } else if (t || !A) {
                c.css({
                    left: u ? 'auto' : (d || o(a)) + '%',
                    right: u ? (d || o(a)) + '%' : 'auto'
                });
            } else {
                y.css('width', (d || o(a)) + '%');
            }
            if (B) {
                U.eq(b).html(a);
            }
            if (a > k) {
                c.removeClass('mbsc-slider-start');
            } else if (i[b] > k || l) {
                c.addClass('mbsc-slider-start');
            }
            if (!t && (i[b] != a || l)) {
                h._display(a);
            }
            if (j && i[b] != a) {
                I = true;
                i[b] = a;
                h._fillValue(a, b, f);
            }
            g.attr('aria-valuenow', a);
        }
        b.classes.Progress.call(this, K, a5, true);
        h._onTap = f;
        h.__onInit = f;
        h._readValue = function(a) {
            return +a.val();
        };
        h._fillValue = function(b, a, c) {
            j.eq(a).val(b);
            if (c) {
                j.eq(a).trigger('change');
            }
        };
        h._attachChange = function() {
            j.on(m.changeEvent, _);
        };
        h._onInit = function(d) {
            var b, c, f;
            if (n) {
                n.removeClass('mbsc-slider-has-tooltip');
                if (l != 1) {
                    a('.mbsc-slider-step', q).remove();
                }
            }
            h.__onInit();
            n = h._$parent;
            q = h._$track;
            y = h._$progress;
            j = n.find('input');
            m = h.settings;
            k = h._min;
            p = h._max;
            l = d.step === e ? +j.attr('step') || m.step : d.step;
            a3 = N('data-live', m.live);
            B = N('data-tooltip', m.tooltip);
            A = N('data-highlight', m.highlight) && j.length < 3;
            P = l % 1 !== 0 ? 100 / (+(l % 1).toFixed(2) * 100) : 1;
            H = 100 / (p - k) || 100;
            t = j.length > 1;
            Q = A && j.length == 2;
            u = m.rtl;
            i = [];
            if (B) {
                n.addClass('mbsc-slider-has-tooltip');
            }
            if (l != 1) {
                c = (p - k) / l;
                for (b = 0; b <= c; ++b) {
                    q.append('<span class="mbsc-slider-step" style="' + (u ? 'right' : 'left') + ':' + 100 / c * b + '%"></span>');
                }
            }
            if (s) {
                f = true;
                s.parent().remove();
            }
            j.each(function(b) {
                i[b] = h._readValue(a(this));
                a(this).attr('data-index', b).attr('min', k).attr('max', p).attr('step', l);
                if (m.handle) {
                    (A ? y : q).append('<span class="mbsc-slider-handle-cont' + (Q && !b ? ' mbsc-slider-handle-left' : '') + '">' + '<span tabindex="0" class="mbsc-slider-handle" aria-valuemin="' + k + '" aria-valuemax="' + p + '" data-index="' + b + '"></span>' + (B ? '<span class="mbsc-slider-tooltip"></span>' : '') + '</span>');
                }
            });
            s = n.find('.mbsc-slider-handle');
            U = n.find('.mbsc-slider-tooltip');
            R = n.find(t ? '.mbsc-slider-handle-cont' : '.mbsc-progress-cont');
            s.on('keydown', a1).on('keyup', F).on('blur', F);
            R.on('touchstart mousedown', W).on('touchmove', D).on('touchend touchcancel', E).on('pointercancel', Z);
            if (!f) {
                j.on('click', $);
                n.on('click', a0);
            }
        };
        h._onDestroy = function() {
            n.off('click', a0);
            j.off(m.changeEvent, _).off('click', $);
            s.off('keydown', a1).off('keyup', F).off('blur', F);
            R.off('touchstart mousedown', W).off('touchmove', D).off('touchend', E).off('touchcancel pointercancel', Z);
        };
        h.refresh = function() {
            j.each(function(b) {
                v(h._readValue(a(this)), b, true, false, true, false);
            });
        };
        h.getVal = function() {
            return t ? i.slice(0) : i[0];
        };
        h.setVal = h._setVal = function(b, d, c) {
            if (!a.isArray(b)) {
                b = [b];
            }
            a.each(b, function(a, b) {
                v(b, a, true, false, true, c);
            });
        };
        if (!a6) {
            h.init(a5);
        }
    };
    b.classes.Slider.prototype = {
        _class: 'progress',
        _css: 'mbsc-progress mbsc-slider',
        _hasTheme: true,
        _hasLang: true,
        _wrap: true,
        _defaults: {
            changeEvent: 'change',
            stopProp: true,
            min: 0,
            max: 100,
            step: 1,
            live: true,
            highlight: true,
            handle: true,
            round: true,
            returnAffix: true
        }
    };
    b.presetShort('slider', 'Slider');
}());
